<script setup lang="ts">
import { ref } from "vue";
import { useContest } from "./hook";
import { PureTableBar } from "@/components/RePureTableBar";
import { useRenderIcon } from "@/components/ReIcon/src/hooks";
import Delete from "@iconify-icons/ep/delete";
import EditPen from "@iconify-icons/ep/edit-pen";
import AddFill from "@iconify-icons/ri/add-circle-line";

defineOptions({
  name: "Contest"
});

const addDtoRef = ref();
const {
  rules,
  loading,
  columns,
  dataList,
  pagination,
  loadingTitle,
  updateContestDto,
  updatePanelVisible,
  onSearch,
  handleUpdate,
  handleDelete,
  handleSizeChange,
  ClosePanelVisible,
  handleCurrentChange,
  handleSelectionChange,
  updateContest
} = useContest();
</script>

<template>
  <div class="main">
    <el-dialog v-model="updatePanelVisible" :title="loadingTitle" width="30%" @close="ClosePanelVisible(addDtoRef)"
      center>
      <el-form label-position="left" label-width="100px" ref="addDtoRef" :rules="rules" :model="updateContestDto"
        style="max-width: 460px">
        <el-form-item label="竞赛名称" prop="ContestName">
          <el-input v-model="updateContestDto.ContestName" />
        </el-form-item>
        <el-form-item label="备注" prop="Remarks">
          <el-input type="textarea" v-model="updateContestDto.Remarks" />
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="updateContest(addDtoRef)">
            保存
          </el-button>
          <el-button @click="ClosePanelVisible(addDtoRef)">取消</el-button>
        </span>
      </template>
    </el-dialog>

    <PureTableBar title="竞赛列表" @refresh="onSearch">
      <template #buttons>
        <el-button type="primary" :icon="useRenderIcon(AddFill)" @click="handleUpdate(undefined)">
          添加竞赛
        </el-button>
      </template>
      <template v-slot="{ size, checkList }">
        <pure-table border align-whole="center" showOverflowTooltip table-layout="auto" :loading="loading" :size="size"
          :data="dataList" :columns="columns" :checkList="checkList" :pagination="pagination"
          :paginationSmall="size === 'small' ? true : false" :default-sort="{ prop: 'createTime', order: 'descending' }"
          :header-cell-style="{
            background: 'var(--el-table-row-hover-bg-color)',
            color: 'var(--el-text-color-primary)'
          }" @selection-change="handleSelectionChange" @size-change="handleSizeChange"
          @current-change="handleCurrentChange">
          <template #operation="{ row }">
            <el-button class="reset-margin" link type="primary" :size="size" :icon="useRenderIcon(EditPen)"
              @click="handleUpdate(row)">
              修改
            </el-button>
            <el-button class="reset-margin" link type="danger" :size="size" :icon="useRenderIcon(Delete)"
              @click="handleDelete(row)">
              删除
            </el-button>
            <!-- <el-popconfirm title="是否确认删除?" @confirm="handleDelete(row)">
              <template #reference>
                <el-button class="reset-margin" link type="danger" :size="size" :icon="useRenderIcon(Delete)">
                  删除
                </el-button>
              </template>
            </el-popconfirm> -->
          </template>
        </pure-table>
      </template>
    </PureTableBar>
  </div>
</template>

<style scoped lang="scss">
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}
</style>
